﻿using System;
using System.IO;
using System.Text;

namespace msilgc.common {
    public static class Logger {

        private static FileInfo _logFileName;
        private static FileInfo LogFileName {
            get {
                if (_logFileName == null) {
                    _logFileName = new FileInfo(string.Format("{0}.log", System.Diagnostics.Process.GetCurrentProcess().ProcessName));
                }
                return _logFileName;
            }
        }

        public static void WriteLine(string format, params string[] param) {
            var msg = string.Format(format, param);
            WriteConsole(msg);
            WriteLog(msg);
        }

        private static void WriteConsole(string msg) {
            Console.WriteLine(msg);
            Console.Out.Flush();
        }

        private static void WriteLog(string msg) {
            using (var writer = new StreamWriter(LogFileName.FullName, true, Encoding.Unicode)) {
                writer.WriteLine(msg);
            }
        }
    }
}
